package SecondeStage.XianCheng;

public class ShouHuThread {
    public static void main(String[] args) throws InterruptedException {
        // 如果我们希望主线程结束后，子线程自动结束,只需要将子线程设为守护线程
        MyDaemonThread myDaemonThread = new MyDaemonThread();
        myDaemonThread.setDaemon(true);
        myDaemonThread.start();

        for (int i = 0; i < 10; i++) {
            Thread.sleep(1000);
            System.out.println("c在辛苦的工作....");
        }
    }
}

class MyDaemonThread extends Thread{
    @Override
    public void run() {
        for (;;){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("a和b在愉快的聊天....");
        }
    }
}